<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <h2>{{fullName}}</h2>
  </div>

  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        firstName: 'Chen',
        lastName: 'YiJia'
      },
      computed: {
        // 这种其实是一种简写
        // fullName: function () {
        //   return this.firstName + ' ' + this.lastName
        // }

        // 计算属性一般是没有set方法,只读属性
        fullName: {
          // 一般情况下set为空,因为不希望别人给计算属性设置值 (给fullName设置值)
          // 改变的也是fullName
          set: function (newValue) {
            console.log('----------------', newValue);
            const names = newValue.split(' ')
            this.firstName = names[0]
            this.lastName = names[1]
          },
          get: function () {
            return this.firstName + ' ' + this.lastName
          }
        }
      },
      methods: {}
    });
  </script>
</body>

</html>